/*******************************************************************************

        copyright:      Copyright (c) 2004 Kris Bell. All rights reserved

        license:        BSD style: $(LICENSE)

        version:        Initial release: Oct 2004

        authors:        Kris
                        Wei "oldrev" Li

        For details on Unicode processing see:
        $(UL $(LINK http://www.utf-8.com/))
        $(UL $(LINK http://www.hackcraft.net/xmlUnicode/))
        $(UL $(LINK http://www.azillionmonkeys.com/qed/unicode.html/))
        $(UL $(LINK http://icu.sourceforge.net/docs/papers/forms_of_unicode/))

*******************************************************************************/

module windump.utf;

import std.utf;

/////////////////////////////
// from tango.std.stringz


version(D_Version2)
{
    /*
    string toUtf8(immutable(wchar)* s)
    {
        return toUTF8(fromUtf16z(s));
    }

    immutable(wchar)* toUtf16z(string s)
    {
        return toUtf16z(toUTF16(s));
    }

    immutable(char)* toUtf8z (string s)
    {
        if (s.ptr)
            s ~= '\0';
        return s.ptr;
    }

    string fromUtf8z (immutable(char)* s)
    {
        return s ? s[0 .. strlenz(s)] : null;
    }

    immutable(wchar)* toUtf16z (wstring s)
    {
        if (s.ptr)
            s ~= "\0"w;
        return s.ptr;
    }

    wstring fromUtf16z (immutable(wchar)* s)
    {
        return s ? s[0 .. strlenz(s)] : null;
    }

    size_t strlenz(T) (immutable(T)* s)
    {
        size_t i;

        if (s)
            while (*s++)
                ++i;
        return i;
    }*/
}
else { // D 1.0

    string toUtf8(wchar* s)
    {
        return toUTF8(fromUtf16z(s));
    }

    wchar* toUtf16z(string s)
    {
        return toUtf16z(toUTF16(s));
    }

    char* toUtf8z (string s)
    {
        if (s.ptr)
            s ~= '\0';
        return s.ptr;
    }

    string fromUtf8z (char* s)
    {
        return s ? s[0 .. strlenz(s)] : null;
    }

    wchar* toUtf16z (wstring s)
    {
        if (s.ptr)
            s ~= "\0"w;
        return s.ptr;
    }

    wstring fromUtf16z (wchar* s)
    {
        return s ? s[0 .. strlenz(s)] : null;
    }

    size_t strlenz(T) (T* s)
    {
        size_t i;

        if (s)
            while (*s++)
                ++i;
        return i;
    }
}

